<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title>Redis Rdb Aof恢复 - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="Redis Rdb Aof恢复">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content="Redis Rdb Aof恢复 - 天地维杰网" />
    <meta name="description" content="现在通过cachecloud创建一个测试集群，测试rdb和aof的备份与恢复" />
     
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/redis-rdb-aof-data-restore/" itemprop="url">
        Redis Rdb Aof恢复
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2022-10-04">
    2022-10-04
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/redis" itemprop="url" rel="index">
        <span itemprop="name">redis</span>
      </a>
      &nbsp; 
    </span>
  
</span>


      
 <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">原创</span>
</span>

       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">1140 字 ~3分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    

    

<h3 id="rdb恢复">RDB恢复</h3>

<p>虚拟机搭建cachecloud测试服务参考文档：<a href="https://blog.csdn.net/wejack/article/details/120569162">https://blog.csdn.net/wejack/article/details/120569162</a></p>

<p>现在通过cachecloud创建一个测试集群，测试rdb和aof的备份与恢复</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220129164451.png" width = 900 /> </div>

<p>通过连接节点服务，可以查看到缓存实例备份文件的目录为 <code>/opt/cachecloud/data</code></p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">&gt;redis-cli -h 10.4.7.212 -p <span style="color:#0000cf;font-weight:bold">6450</span>
10.4.7.212:6450&gt; auth 84eefb67aad12bbd1428786f6d137408
OK
10.4.7.212:6450&gt; config get dir
1<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;dir&#34;</span>
2<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;/opt/cachecloud/data&#34;</span>
<span style="color:#8f5902;font-style:italic"># config get save命令可以看到rdb备份频次设置</span>
10.4.7.212:6450&gt; config get save
1<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;save&#34;</span>
2<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;&#34;</span></code></pre></div>
<p>或者登录实例所在的服务器，直接查看实例的配置文件，也可以看到相应配置</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@m212 ~<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># cat /opt/cachecloud/conf/redis-cluster-6450.conf</span>
daemonize no
tcp-backlog <span style="color:#0000cf;font-weight:bold">511</span>
timeout <span style="color:#0000cf;font-weight:bold">0</span>
tcp-keepalive <span style="color:#0000cf;font-weight:bold">60</span>
loglevel notice
databases <span style="color:#0000cf;font-weight:bold">16</span>
dir <span style="color:#4e9a06">&#34;/opt/cachecloud/data&#34;</span>

appendonly yes
appendfsync everysec
appendfilename <span style="color:#4e9a06">&#34;appendonly-6450.aof&#34;</span>
dbfilename <span style="color:#4e9a06">&#34;dump-6450.rdb&#34;</span>
aof-rewrite-incremental-fsync yes
no-appendfsync-on-rewrite yes
auto-aof-rewrite-min-size 62500kb
auto-aof-rewrite-percentage <span style="color:#0000cf;font-weight:bold">87</span></code></pre></div>
<p><font color=red>要使用rdb恢复数据，需要将配置文件的<code>appendonly yes</code>设置为no，否则实例重启以后不会读取rdb文件进行恢复</font></p>

<p><font color=red>另外要注意，如果是使用集群的某一个主节点实例进行测试，要将其从节点下线，否则可能会因为主节点重启导致主从切换，导致数据恢复失败</font></p>

<p>连接redis实例，执行bgsave命令即执行rdb持久化</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.212:6450&gt; bgsave
Background saving started</code></pre></div>
<p>在相应的数据目录可以看到相应的数据文件</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@m212 data<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># ls -l | grep 6450</span>
-rw-r--r--. <span style="color:#0000cf;font-weight:bold">1</span> cachecloud-open cachecloud-open   <span style="color:#0000cf;font-weight:bold">8575680</span> 1月  <span style="color:#0000cf;font-weight:bold">29</span> 16:38 appendonly-6450.aof
-rw-rw-r--. <span style="color:#0000cf;font-weight:bold">1</span> cachecloud-open cachecloud-open   <span style="color:#0000cf;font-weight:bold">1083576</span> 1月  <span style="color:#0000cf;font-weight:bold">29</span> 16:49 dump-6450.rdb</code></pre></div>
<p>在redis实例上执行flushdb清空数据，并删除data中的aof备份文件，可以查看到实例数据已被清空。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">10.4.7.212:6450&gt; flushall
OK
10.4.7.212:6450&gt; keys *
<span style="color:#ce5c00;font-weight:bold">(</span>empty list or <span style="color:#204a87">set</span><span style="color:#ce5c00;font-weight:bold">)</span></code></pre></div>
<p>重启实例</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@m212 logs<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># sudo su - cachecloud-open -c &#39;/opt/cachecloud/redis-3.2.12/src/redis-server /opt/cachecloud/conf/redis-cluster-6450.conf &gt; /opt/cachecloud/logs/redis-6450-`date +%Y%m%d%H%M`.log 2&gt;&amp;1 &amp;&#39;</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@m212 logs<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># ps -ef | grep 6450</span>
cachecl+  <span style="color:#0000cf;font-weight:bold">97203</span>      <span style="color:#0000cf;font-weight:bold">1</span>  <span style="color:#0000cf;font-weight:bold">0</span> 17:05 ?        00:00:00 /opt/cachecloud/redis-3.2.12/src/redis-server 0.0.0.0:6450 <span style="color:#ce5c00;font-weight:bold">[</span>cluster<span style="color:#ce5c00;font-weight:bold">]</span></code></pre></div>
<p>查看redis日志，可以看到加载了数据。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@m212 logs<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># tail -500f /opt/cachecloud/logs/redis-6450-202201291821.log</span>
<span style="color:#4e9a06">`</span>-.__.-<span style="color:#a40000">&#39;</span>

100017:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 18:21:06.266 <span style="color:#8f5902;font-style:italic"># Server started, Redis version 3.2.12</span>
100017:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 18:21:06.315 * DB loaded from disk: 0.049 seconds
100017:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 18:21:06.316 * The server is now ready to accept connections on port <span style="color:#0000cf;font-weight:bold">6450</span>
100017:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 18:21:08.339 <span style="color:#8f5902;font-style:italic"># Cluster state changed: ok</span></code></pre></div>
<p>再连接实例查看，数据已经恢复。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">10.4.7.212:6450&gt; keys *
  1<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_bigstr_00000013&#34;</span>
  2<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_biglist_00000053&#34;</span>
  3<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_list_00000098&#34;</span>
  4<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_abigzset_00000059&#34;</span>
  5<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_list_00000087&#34;</span>
  6<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_set_00000063&#34;</span></code></pre></div>
<h3 id="aof恢复">AOF恢复</h3>

<p>首先修改缓存实例配置文件，打开aof持久化，将appendonly 属性改为yes</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">appendonly yes</code></pre></div>
<p>插入一批数据以后，可以看到有数据</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">10.4.7.212:6450&gt; keys *
  1<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_hash_00000012&#34;</span>
  2<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_bighash_00000024&#34;</span>
  3<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_hash_00000079&#34;</span>
  4<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_bigstr_00000063&#34;</span>
  5<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_bigset_00000051&#34;</span>
  6<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello00000031&#34;</span></code></pre></div>
<p>查看aof持久化文件，可以看到有相应命令</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@m212 data<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># tail -50f /opt/cachecloud/data/appendonly-6450.aof</span>
cj:hello_abigzset_00000099
<span style="color:#000">$2</span>
<span style="color:#0000cf;font-weight:bold">59</span>
<span style="color:#000">$5</span>
YBxAh
*4
<span style="color:#000">$4</span>
ZADD
<span style="color:#000">$26</span>
cj:hello_abigzset_00000099
<span style="color:#000">$2</span></code></pre></div>
<p>执行flushall将实例的数据清空</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">10.4.7.212:6450&gt; flushall
OK
10.4.7.212:6450&gt; keys *
<span style="color:#ce5c00;font-weight:bold">(</span>empty list or <span style="color:#204a87">set</span><span style="color:#ce5c00;font-weight:bold">)</span></code></pre></div>
<p>可以看到aof持久化文件的末尾有flushall命令</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">data<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># less /opt/cachecloud/data/appendonly-6450.aof</span>
……省略……
<span style="color:#0000cf;font-weight:bold">0</span>
*1
<span style="color:#000">$8</span>
flushall
<span style="color:#ce5c00;font-weight:bold">(</span>END<span style="color:#ce5c00;font-weight:bold">)</span></code></pre></div>
<p>编辑aof配置文件，将末尾行的flushall命令删除并保存，然后重启redis实例，查看缓存日志，可以看到从aof持久化文件加载了数据。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@m212 logs<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># tail -500f /opt/cachecloud/logs/redis-6450-202201291936.log</span>
102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:15.090 * Increased maximum number of open files to <span style="color:#0000cf;font-weight:bold">4096</span> <span style="color:#ce5c00;font-weight:bold">(</span>it was originally <span style="color:#204a87">set</span> to 1024<span style="color:#ce5c00;font-weight:bold">)</span>.
102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:15.090 * Node configuration loaded, I<span style="color:#4e9a06">&#39;m 5d9a574bbcd42451079e3b4daecd7c329104c7e6
</span><span style="color:#4e9a06">                _._
</span><span style="color:#4e9a06">           _.-``__ &#39;</span><span style="color:#4e9a06">&#39;-._
</span><span style="color:#4e9a06">      _.-``    `.  `_.  &#39;</span><span style="color:#4e9a06">&#39;-._           Redis 3.2.12 (00000000/0) 64 bit
</span><span style="color:#4e9a06">  .-`` .-```.  ```\/    _.,_ &#39;</span><span style="color:#4e9a06">&#39;-._
</span><span style="color:#4e9a06"> (    &#39;</span>      ,       .-<span style="color:#4e9a06">`</span>  <span style="color:#000;font-weight:bold">|</span> <span style="color:#4e9a06">`</span>,    <span style="color:#ce5c00;font-weight:bold">)</span>     Running in cluster mode
 <span style="color:#000;font-weight:bold">|</span><span style="color:#4e9a06">`</span>-._<span style="color:#4e9a06">`</span>-...-<span style="color:#4e9a06">`</span> __...-.<span style="color:#4e9a06">`</span><span style="color:#4e9a06">`</span>-._<span style="color:#000;font-weight:bold">|</span><span style="color:#4e9a06">&#39;` _.-&#39;</span><span style="color:#000;font-weight:bold">|</span>     Port: <span style="color:#0000cf;font-weight:bold">6450</span>
 <span style="color:#000;font-weight:bold">|</span>    <span style="color:#4e9a06">`</span>-._   <span style="color:#4e9a06">`</span>._    /     _.-<span style="color:#4e9a06">&#39;    |     PID: 102639
</span><span style="color:#4e9a06">  `-._    `-._  `-./  _.-&#39;</span>    _.-<span style="color:#4e9a06">&#39;
</span><span style="color:#4e9a06"> |`-._`-._    `-.__.-&#39;</span>    _.-<span style="color:#4e9a06">&#39;_.-&#39;</span><span style="color:#000;font-weight:bold">|</span>
 <span style="color:#000;font-weight:bold">|</span>    <span style="color:#4e9a06">`</span>-._<span style="color:#4e9a06">`</span>-._        _.-<span style="color:#4e9a06">&#39;_.-&#39;</span>    <span style="color:#000;font-weight:bold">|</span>           http://redis.io
  <span style="color:#4e9a06">`</span>-._    <span style="color:#4e9a06">`</span>-._<span style="color:#4e9a06">`</span>-.__.-<span style="color:#4e9a06">&#39;_.-&#39;</span>    _.-<span style="color:#4e9a06">&#39;
</span><span style="color:#4e9a06"> |`-._`-._    `-.__.-&#39;</span>    _.-<span style="color:#4e9a06">&#39;_.-&#39;</span><span style="color:#000;font-weight:bold">|</span>
 <span style="color:#000;font-weight:bold">|</span>    <span style="color:#4e9a06">`</span>-._<span style="color:#4e9a06">`</span>-._        _.-<span style="color:#4e9a06">&#39;_.-&#39;</span>    <span style="color:#000;font-weight:bold">|</span>
  <span style="color:#4e9a06">`</span>-._    <span style="color:#4e9a06">`</span>-._<span style="color:#4e9a06">`</span>-.__.-<span style="color:#4e9a06">&#39;_.-&#39;</span>    _.-<span style="color:#4e9a06">&#39;
</span><span style="color:#4e9a06">      `-._    `-.__.-&#39;</span>    _.-<span style="color:#4e9a06">&#39;
</span><span style="color:#4e9a06">          `-._        _.-&#39;</span>
              <span style="color:#4e9a06">`</span>-.__.-<span style="color:#a40000">&#39;</span>

102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:15.091 <span style="color:#8f5902;font-style:italic"># Server started, Redis version 3.2.12</span>
102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:15.366 <span style="color:#8f5902;font-style:italic"># !!! Warning: short read while loading the AOF file !!!</span>
102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:15.366 <span style="color:#8f5902;font-style:italic"># !!! Truncating the AOF at offset 8575833 !!!</span>
102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:15.366 <span style="color:#8f5902;font-style:italic"># AOF loaded anyway because aof-load-truncated is enabled</span>
102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:15.366 * DB loaded from append only file: 0.276 seconds
102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:15.367 * The server is now ready to accept connections on port <span style="color:#0000cf;font-weight:bold">6450</span>
102639:M <span style="color:#0000cf;font-weight:bold">29</span> Jan 19:36:17.392 <span style="color:#8f5902;font-style:italic"># Cluster state changed: ok</span></code></pre></div>
<p>查看实例可以看到恢复了数据</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">10.4.7.212:6450&gt; keys *
  1<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_bighash_00000099&#34;</span>
  2<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_biglist_00000022&#34;</span>
  3<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_biglist_00000017&#34;</span>
  4<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_bighash_00000091&#34;</span>
  5<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_hash_00000030&#34;</span>
  6<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#4e9a06">&#34;cj:hello_set_00000049&#34;</span></code></pre></div>
    </div>
    <footer class="post-footer">
     
 
<div class="post-tags">     
     
    <a href="http://www.shutdown.cn/tags/redis" rel="tag" title="redis">#redis#</a>
    
    <a href="http://www.shutdown.cn/tags/rdb" rel="tag" title="rdb">#rdb#</a>
    
    <a href="http://www.shutdown.cn/tags/aof" rel="tag" title="aof">#aof#</a>
    
    <a href="http://www.shutdown.cn/tags/%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d" rel="tag" title="数据恢复">#数据恢复#</a>
    
</div>



     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/understand-redis-sds/" rel="next" title="redis 系列，要懂redis，首先得看懂sds（全网最细节的sds讲解）">
        <i class="fa fa-chevron-left"></i> redis 系列，要懂redis，首先得看懂sds（全网最细节的sds讲解）
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/cpu-affinity-in-linux/" rel="prev" title="Linux中CPU亲和性（affinity）">
        Linux中CPU亲和性（affinity） <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

  <ul class="sidebar-nav motion-element">
    <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
      文章目录
    </li>
    <li class="sidebar-nav-overview" data-target="site-overview">
      站点概览
    </li>
  </ul>

    <section class="site-overview sidebar-panel ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
<section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
    <div class="post-toc">
        <div class="post-toc-content"><nav id="TableOfContents">
<ul>
<li>
<ul>
<li>
<ul>
<li><a href="#rdb恢复">RDB恢复</a></li>
<li><a href="#aof恢复">AOF恢复</a></li>
</ul></li>
</ul></li>
</ul>
</nav></div>
    </div>
</section>

  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>